<?php

	// +----------------------------------------------------------------------
	// | 中国省市区三级联动插件的后台控制器
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace addon\china_city\controller;

	use addon\china_city\model\District as DistrictModel;
	use yicmf\addon\controller\AdminController;
	use yicmf\builder\Edit;
	use yicmf\builder\Table;

	class Admin extends AdminController
	{
		// 默认配置
		public function config()
		{

			$config = $this->getConfig();
			$config['addon_name'] = $this->getName();
			$builder = new Edit();
			$builder->title('三级联动插件')
				->keyHidden('addon_name')
				->keyCity('district', '默认城市选择', '设置默认城市')//['province', 'city', 'district']
//             ->explain('配置')
				->data($config)
				->buttonSubmit('', '保存');
			return $builder->fetch();
		}

		public function index()
		{
			$map = [];
			$map[] = ['status', '=', 1];
			$map[] = ['upid', '=', 0];
//			$map[] = ['status', '=', 1];
			// 显示页面
			$builder = new Table();
			$builder->model(DistrictModel::class)
				->where($map)
				->order('id ASC')
//				->suggest('支持当前页面参数的调用，例如：{$data.title}')
				->searchText('name', '名称')
//				->buttonUpdate('admin/Seo/update')
				->keyId()
				->keyText('name', '名称')
				->keyText('pinyin', '拼音')
				->keyText('lon', '经度')
				->keyText('lat', '纬度')
  				->keyUpdateTime()
				->actionUpdate()
				->actionDelete();
			return $builder->fetch();
		}
	}
